<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * @author duongbq
 * Date 2011 - 05 -11
 */
class Tag_Model extends CI_Model
{
    public function __construct() {
        parent::__construct();
    }
    
    /**
     * @author duongbq
     * @param type $params
     * @return type 
     */
    function get_tag($params = array())
    {
        //Where_______________________________________
        
        if(isset ($params['tag_name']))
            $this->db->where('tag_name', $params['tag_name']);
        
        if(isset ($params['order_by']))
            $this->db->order_by($params['order_by']);
        else
            $this->db->order_by('tag_name');
            
        return $this->db->get('tag')->result();        
    }
    
    function get_tags_array($params = array())
    {
        $tags = $this->get_tags($params);
        $output = array();
        foreach($tags as $item)
        {
            $output[$item->id] = $item->tag_name;
        }
        return $output;
    }
    
    public function add_tag($data = array())
    {
        $this->db->insert('tag', $data);
        return $this->db->insert_id();//@duongbq: trả về tag_id vừa insert
    }
    
    function delelte_tag($data = array()) {
        if (isset($data['id']))
            $this->db->where('tag.id', $data['id']);

        return $this->db->delete('tag');
    }
    
}
